package com.gdk.ksoft.ui.reporters.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gdk.ksoft.R;
import com.gdk.ksoft.assembly.utils.extensions.FormatUtils;

import java.util.HashMap;
import java.util.List;

/**
 * Created by hel on 2014-12-19.
 * 客户欠款查询数据适配器
 */
public class DebtStatementAdapter extends BaseAdapter {

    private Context context;
    private List<HashMap<String,Object>> list;

    public DebtStatementAdapter(Context context,List<HashMap<String,Object>> list){
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final HashMap<String,Object> item = list.get(position);
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_pdebtstatement_lstdebt,null);
            holder.txtIcon = (TextView)convertView.findViewById(R.id.item_pdebtStatement_lstdebt_txtIcon);
            holder.txtCustomerName = (TextView)convertView.findViewById(R.id.item_pdebtStatement_lstdebt_txtCustomerName);
            holder.txtCustomerContractor = (TextView)convertView.findViewById(R.id.item_pdebtStatement_lstdebt_txtContactor);
            holder.txtCustomerAddr = (TextView)convertView.findViewById(R.id.item_pdebtStatement_lstdebt_txtAddress);
            holder.txtCustomerDeliver = (TextView)convertView.findViewById(R.id.item_pdebtStatement_lstdebt_txtContacts);
            holder.txtOrderNo = (TextView)convertView.findViewById(R.id.item_pdebtStatement_lstdebt_txtOrderNo);
            holder.txtDebtMoney = (TextView)convertView.findViewById(R.id.item_pdebtStatement_lstdebt_txtDebtMoney);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();
        }
        holder.txtIcon.setText(item.get("kico").toString());
        holder.txtCustomerName.setText(item.get("kmc").toString());
        holder.txtCustomerContractor.setText(item.get("klxr")+" "+item.get("klxrdh"));
        holder.txtCustomerAddr.setText("地址："+item.get("kshdz"));
        holder.txtCustomerDeliver.setText(item.get("kshr")+" "+item.get("kshdh"));
        holder.txtOrderNo.setText(item.get("kdjh").toString());
        holder.txtDebtMoney.setText("未收金额："+FormatUtils.exactNumber(item.get("kwsje"),"0.00")+"元");
        return convertView;
    }


    class ViewHolder{
        public TextView txtIcon,
                        txtCustomerName,
                        txtCustomerContractor,
                        txtCustomerAddr,
                        txtCustomerDeliver,
                        txtOrderNo,
                        txtDebtMoney;
    }
}
